import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
import { Interceptor_NoCache_Base } from './common/interceptors/noCache';
import { Interceptor_ResponseFormat_Base } from './common/interceptors/responseFormat';
import { Guard_JwtAuth_Base } from './common/guards/jwtAuth';
import { RegiestModules } from './modules/modules';
import { RedisModule } from '@nestjs-modules/ioredis';
import { LoggerModule } from 'nestjs-pino';
import { ScheduleModule } from '@nestjs/schedule';
import {
  Others_AppModulesConfig_Config,
  Others_AppModulesConfig_JwtModule,
  Others_AppModulesConfig_Pina,
  Others_AppModulesConfig_Redis,
  Others_AppModulesConfig_TypeOrm,
} from './common/others/appModulesConfig';
import { JwtModule } from '@nestjs/jwt';
import { Class_JwtStrategy_Base } from './common/classes/jwtStrategy';
import { Pipe_ValidatorErrorHander_Base } from './common/pipes/validatorErrorHander';

@Module({
  imports: [
    ScheduleModule.forRoot(),
    LoggerModule.forRoot(Others_AppModulesConfig_Pina),
    RedisModule.forRootAsync(Others_AppModulesConfig_Redis),
    ConfigModule.forRoot(Others_AppModulesConfig_Config),
    TypeOrmModule.forRootAsync(Others_AppModulesConfig_TypeOrm),
    JwtModule.register(Others_AppModulesConfig_JwtModule),
    ...RegiestModules,
  ],
  providers: [
    { provide: APP_INTERCEPTOR, useClass: Interceptor_NoCache_Base },
    { provide: APP_INTERCEPTOR, useClass: Interceptor_ResponseFormat_Base },
    { provide: APP_GUARD, useClass: Guard_JwtAuth_Base },
    { provide: APP_PIPE, useClass: Pipe_ValidatorErrorHander_Base },
    Class_JwtStrategy_Base,
  ],
})
export class AppModule {}
